package sz.szsmk.citizencard.ui.fragment;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.SearchViewBinding;
import sz.szsmk.citizencard.ioc.Compontent.DaggerCommonFragmentComponent;
import sz.szsmk.citizencard.log.L;
import sz.szsmk.citizencard.model.network.bean.response.SearchViewResponse;
import sz.szsmk.citizencard.mvp.contract.ISearchViewContact;
import sz.szsmk.citizencard.mvp.presenter.SearchViewPresenter;
import sz.szsmk.citizencard.ui.adapter.SearchViewAdapter;
import sz.szsmk.citizencard.ui.base.IBaseFragment;
import sz.szsmk.citizencard.util.Constant;

import java.util.List;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/7/13 10:19
 * description:
 */
public class SearchViewFragment extends IBaseFragment<SearchViewPresenter, SearchViewBinding>
        implements ISearchViewContact.ISearchViewView {

    private SearchViewAdapter searchViewAdapter;

    public static SearchViewFragment getInstance() {
        SearchViewFragment sf = new SearchViewFragment();
        return sf;
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.search_view;
    }

    @Override
    protected void initInjector() {
        DaggerCommonFragmentComponent.builder().appCompontent(DaggerApplication.getAppComponent())
                .build().inject(this);
    }

    @Override
    protected void initViews() {
        RecyclerView searchViewRv = dataBinding.searchViewRv;
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        searchViewRv.setLayoutManager(linearLayoutManager);
        searchViewAdapter = new SearchViewAdapter(getActivity());
        searchViewRv.setAdapter(searchViewAdapter);
        mPresenter.sendReq();
    }

    @Override
    protected void updateViews() {

    }

    @Override
    public void updataError(String message) {

    }

    @Override
    public void getNewsInfoSucc(SearchViewResponse response) {
        L.e(Constant.TAG,"====================================================");
        List<SearchViewResponse.SpotDeatilHotelListBean> spot_deatil_hotel_list = response.getSpot_deatil_hotel_list();
        List<SearchViewResponse.SpotDeatilSpotListBean> spot_deatil_spot_list = response.getSpot_deatil_spot_list();
        if (spot_deatil_spot_list == null){
            return;
        }
        searchViewAdapter.setViewData(spot_deatil_spot_list);
        searchViewAdapter.notifyDataSetChanged();

    }

}
